#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   Excel.py
@Time    :   2020/05/18 17:00:34
@Author  :   Xiong qiufeng
@Version :   1.0
@Contact :   1528399071@qq.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   None
'''
import xlrd

class Excel:

    @staticmethod
    def read_data_rows(file, sheet_name):
        """ 按行读取excel数据 
        @file:
        @sheet_name:
        """
        # 打开excel文件
        data = xlrd.open_workbook(file)
        # 打开sheet
        table = data.sheet_by_name(sheet_name)
        # 行数
        rowNum = int(table.nrows)
        # 列数
        colNum = int(table.ncols)
        # 数据
        data = []
        for row in range(rowNum):
            # 每行的数据
            row_data = []
            for col in range(colNum):
                # 获取(row,col)对应的单元格数据
                value = table.cell_value(row,col)
                row_data.append(value)
            data.append(row_data)
        return data

    @staticmethod
    def read_data_cols(file, sheet_name):
        """ 按列读取excel数据 
        @file:
        @sheet_name:
        """
        # 打开excel文件
        data = xlrd.open_workbook(file)
        # 打开sheet
        table = data.sheet_by_name(sheet_name)
        # 行数
        rowNum = int(table.nrows)
        # 列数
        colNum = int(table.ncols)
        # 数据
        data = []
        for col in range(colNum):
            # 每列的数据
            col_data = []
            for row in range(rowNum):
                # 获取(row,col)对应的单元格数据
                value = table.cell_value(row,col)
                col_data.append(value)
            data.append(col_data)
        return data